<template>
  <div class="page-main" v-title :data-title="dataTitle ? dataTitle : '合同报工任务单'">
    <FixedMenu />
    <home-nav :userData="userinfo"></home-nav>
    <div class="banner"><span>合同报工任务单</span></div>
    <div class="container">
      <div class="header">
        <a-row type="flex" justify="space-between" align="middle">
          <a-col :xl="{ span: 14 }" :lg="{ span: 11 }">
            <a-button
              v-if="checkPermission(['WORK_REPORT_MANAGER'])"
              class="hte-btn add-btn"
              type="primary"
              icon="plus"
              @click="addTaskByProject"
              >创建</a-button
            >
            <a-button
              v-if="checkPermission(['WORK_REPORT_MANAGER', 'WORK_REPORT_ACCEPTER'])"
              class="hte-btn port-btn"
              @click="exportExcle"
              >导出</a-button
            >
            <a-button v-if="checkPermission(['WORK_REPORT_MANAGER'])" class="hte-btn del-btn" @click="removeTask"
              >删除</a-button
            >
            <a-button
              v-if="checkPermission(['WORK_REPORT_ADMIN', 'WORK_REPORT_MANAGER'])"
              class="hte-btn del-btn"
              @click="updateTaskUser"
              >更新项目负责人</a-button
            >
            <a-button
              v-if="checkPermission(['WORK_REPORT_ADMIN', 'WORK_REPORT_MANAGER'])"
              class="hte-btn del-btn"
              @click="
                executeStatus = '5'
                showExecuteStatus = true
              "
              >标记为HIP已完成</a-button
            >
            <a-button
              v-if="checkPermission(['WORK_REPORT_ADMIN', 'WORK_REPORT_MANAGER'])"
              class="hte-btn del-btn"
              @click="
                isPayNode = '1'
                showIsPayNode = true
              "
              >标记为付款节点</a-button
            >
            <a-button class="budget-detail" @click="toFilterTask(2)">
              <a-icon type="frown" style="color: red" />
              <a-badge :offset="[-11, -15]">
                <div class="redRow">工期逾期</div>
              </a-badge>
            </a-button>
            <a-button class="budget-detail" @click="toFilterTask(3)">
              <a-icon type="frown" style="color: red" />
              <a-badge :offset="[-11, -15]">
                <div class="redRow">逾期报工</div>
              </a-badge>
            </a-button>
            <a-button class="budget-detail" @click="toFilterTask(1)">
              <a-icon type="meh" style="color: green" />
              <a-badge :offset="[-11, -15]">
                <div class="greenRow">即将到期</div>
              </a-badge>
            </a-button>
          </a-col>
          <a-col :xl="{ span: 9 }" :lg="{ span: 13 }" class="input-ground">
            <a-input-group compact>
              <a-select v-model="keywordType">
                <a-select-option value="1"> 合同编号 </a-select-option>
                <a-select-option value="2"> 合同名称 </a-select-option>
              </a-select>
              <a-input-search
                v-if="keywordType == '1'"
                v-model="searchForm.contractNumber"
                @search="handleSearch"
                placeholder="请按照关键字进行搜索"
              />
              <a-input-search
                v-if="keywordType == '2'"
                v-model="searchForm.contractName"
                @search="handleSearch"
                placeholder="请按照关键字进行搜索"
              />
            </a-input-group>
            <a-button class="hte-btn del-btn" @click="openSearchForm">高级搜索</a-button>
          </a-col>
        </a-row>
      </div>
      <div class="content-list">
        <a-table
          :scroll="{ x: 1800 }"
          class="hte-table-content"
          :columns="columns"
          :data-source="records"
          :pagination="false"
          :loading="tabLoading"
          rowKey="id"
          :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
          size="middle"
          bordered
          :customRow="customRow"
          @change="handleTableChange"
          :rowClassName="tableRowClass"
        >
          <span slot="purchaseOrderNumberRender" slot-scope="text, record">
            <span class="font-active" @click="toTaskDetail(record)">
              {{ record.purchaseOrderNumber + '(' + record.itemIndex + '/' + record.itemCount + ')' }}</span
            >
          </span>
          <span slot="complateTimeRender" slot-scope="text, record">
            {{ formatDate(record.complateTime || '', 'yyyy-MM-dd') }}
          </span>
          <span slot="planTimeRender" slot-scope="text, record">
            {{ formatDate(record.partaPlanTime || '', 'yyyy-MM-dd') }}
          </span>
          <span slot="actualTimeRender" slot-scope="text, record">
            {{ formatDate(record.partaActualTime || '', 'yyyy-MM-dd') }}
          </span>
          <template slot="isMutiContiditonRender" slot-scope="text, record">
            <template v-for="(code, index) in codes.IsMutiContiditon">
              <span :key="index" v-if="record.isMutiContiditon == code.code">{{ code.name }}</span>
            </template>
          </template>
          <template slot="isPayNodeRender" slot-scope="text, record">
            <template v-for="(code, index) in codes.IsPayNode">
              <span :key="index" v-if="record.isPayNode == code.code">{{ code.name }}</span>
            </template>
          </template>
          <template slot="statusRender" slot-scope="text, record">
            <span v-for="(code, index) in codes.WorkReportTaskStatus" :key="index">
              <i v-if="record.status == code.code">{{ code.name }}</i>
            </span>
          </template>
          <template slot="paymentStatusRender" slot-scope="text, record">
            <span v-for="(code, index) in codes.WorkReportTaskAcceptStatus" :key="index">
              <i v-if="record.acceptStatus == code.code">{{ code.name }}</i>
            </span>
          </template>

          <template slot="nodeStatusRender" slot-scope="text, record">
            {{ calcNodeStatus(record) }}
          </template>
          <template slot="delayReasonRender" slot-scope="text, record">
            <span v-for="(code, index) in codes.WorkReportDelayReson" :key="index">
              <i v-if="record.partaDelayReason == code.code">{{ code.name }}</i>
            </span>
          </template>
          <template slot="nodeContentRender" slot-scope="text, record">
            <span :class="'contentStyle-' + calcDelayType(record)">
              {{ text }}
            </span>
          </template>
          <template slot="paymentContentRender" slot-scope="text, record">
            <span :class="'contentStyle-' + calcDelayType(record)">
              {{ text }}
            </span>
          </template>
        </a-table>
        <a-pagination
          show-size-changer
          :default-current="1"
          :total="searchForm.total"
          @change="pageChange"
          @showSizeChange="onShowSizeChange"
          :show-total="(total) => `共 ${total} 条记录`"
        />
      </div>
    </div>
    <a-back-top class="backtodom" />
    <a-modal
      :visible="showSearchForm"
      width="70vw"
      :bodyStyle="{ padding: '10px' }"
      title="高级查询"
      @ok="handleToSearch"
      @cancel="handleToCancel"
    >
      <a-form-model ref="ruleForm" :label-col="labelCol" :wrapper-col="wrapperCol" @keyup.enter.native="handleToSearch">
        <a-row :gutter="24">
          <a-col :span="8">
            <a-form-model-item label="任务状态">
              <a-select mode="multiple" v-model="searchForm.statusArr" style="width: 100%" allowClear>
                <a-select-option v-for="(code, index) in codes.WorkReportTaskStatus" :key="index" :value="code.code">
                  {{ code.name }}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="合同编号">
              <a-input allow-clear v-model="searchForm.contractNumber" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="合同名称">
              <a-input allow-clear v-model="searchForm.contractName" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="8">
            <a-form-model-item label="合同跟进专员">
              <a-input allow-clear v-model="searchForm.createOrderUser" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="项目经理">
              <a-input allow-clear v-model="searchForm.proManager" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="项目负责人">
              <a-input allow-clear v-model="searchForm.followPerson" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="8">
            <a-form-model-item label="签订公司">
              <a-input allow-clear v-model="searchForm.signCompany" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="供应商名称">
              <a-input allow-clear v-model="searchForm.supplierName" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="合同签订人">
              <a-input allow-clear v-model="searchForm.createUder" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="8">
            <a-form-model-item label="采购订单号">
              <a-input allow-clear v-model="searchForm.purchaseOrderNumber" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="费用支出号">
              <a-input allow-clear v-model="searchForm.costNumber" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="发起验收">
              <a-select mode="multiple" v-model="searchForm.acceptStatusArr" style="width: 100%" allowClear>
                <a-select-option
                  v-for="(code, index) in codes.WorkReportTaskAcceptStatus"
                  :key="index"
                  :value="code.code"
                >
                  {{ code.name }}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="16">
            <a-form-model-item label="合同约定时间">
              <a-range-picker
                v-model="complateTime"
                :show-time="{ format: 'YYYY-MM-DD' }"
                valueFormat="YYYY-MM-DD"
                format="YYYY-MM-DD"
                :placeholder="['开始时间', '结束时间']"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="工期状态">
              <a-select v-model="searchForm.partaNodeStatus" style="width: 100%" allowClear>
                <a-select-option value="全部">全部</a-select-option>
                <a-select-option value="正常">正常</a-select-option>
                <a-select-option value="逾期">逾期</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-modal>
    <RelpaceHandlerUserByTask
      :show="showRelpaceHandlerUserByTask"
      :permission="permission"
      @close="closeRelpaceHandlerUserByTask"
      :taskIds="selectedRowKeys"
    />

    <a-modal
      :visible="showExecuteStatus"
      width="20vw"
      :bodyStyle="{ padding: '10px' }"
      title="标记HIP已完成"
      @ok="updateExecuteStatus"
      @cancel="showExecuteStatus = false"
    >
      <a-form-model ref="ruleForm" :label-col="labelCol" :wrapper-col="wrapperCol" @keyup.enter.native="handleToSearch">
        <a-form-model-item label="HIP已完成">
          <a-select v-model="executeStatus" style="width: 100%" allowClear>
            <a-select-option
              v-for="(code, index) in [
                { code: '5', name: '是' },
                { code: '', name: '否' },
              ]"
              :key="index"
              :value="code.code"
            >
              {{ code.name }}
            </a-select-option>
          </a-select>
        </a-form-model-item>
      </a-form-model>
    </a-modal>
    <a-modal
      :visible="showIsPayNode"
      width="20vw"
      :bodyStyle="{ padding: '10px' }"
      title="标记付款节点"
      @ok="updateIsPayNode"
      @cancel="showIsPayNode = false"
    >
      <a-form-model ref="ruleForm" :label-col="labelCol" :wrapper-col="wrapperCol" @keyup.enter.native="handleToSearch">
        <a-form-model-item label="付款节点">
          <a-select v-model="isPayNode" style="width: 100%" allowClear>
            <a-select-option
              v-for="(code, index) in [
                { code: '1', name: '是' },
                { code: '0', name: '否' },
              ]"
              :key="index"
              :value="code.code"
            >
              {{ code.name }}
            </a-select-option>
          </a-select>
        </a-form-model-item>
      </a-form-model>
    </a-modal>
  </div>
</template>
<script>
import { getAction, postAction } from '@/api/manage'
import { formatDate, calcDaysBetween } from '@/utils/util'
import { UtilsMixin } from '@/mixins/UtilsMixin'
import { Modal } from 'ant-design-vue'
export default {
  mixins: [UtilsMixin],
  name: 'ContractTaskList',
  components: {
    HomeNav: () => import('@/components/layouts/HomeNav'),
    RelpaceHandlerUserByTask: () => import('@/views/workReport/util/RelpaceHandlerUserByTask'),
    FixedMenu: () => import('@/views/workReport/home/FixedMenu'),
  },
  data() {
    return {
      dataTitle: this.$route ? this.$route.name : '',
      userinfo: {
        info: this.$store.getters.userInfo,
        module: 'ContractTaskList',
      },

      labelCol: { span: 8 },
      wrapperCol: { span: 15 },
      columns: [
        {
          title: '任务状态',
          dataIndex: 'status',
          align: 'center',
          scopedSlots: { customRender: 'statusRender' },
          width: '130px',
          ellipsis: true,
        },
        {
          title: '发起验收',
          dataIndex: 'paymentStatus',
          align: 'center',
          scopedSlots: { customRender: 'paymentStatusRender' },
          width: '110px',
          ellipsis: true,
        },
        {
          title: '报工单编号',
          dataIndex: 'itemIndex',
          align: 'center',
          sorter: true,
          scopedSlots: { customRender: 'purchaseOrderNumberRender' },
          width: '160px',
          ellipsis: true,
        },
        {
          title: 'PO单行号',
          dataIndex: 'poLine',
          align: 'center',
          width: '80px',
          ellipsis: true,
        },
        {
          title: '合同名称',
          dataIndex: 'contractName',
          align: 'center',
          width: '140px',
          ellipsis: true,
        },
        {
          title: '工期节点内容',
          dataIndex: 'nodeContent',
          align: 'center',
          width: '140px',
          customCell: () => {
            return {
              style: {
                width: '140px',
                overflow: 'hidden',
                whiteSpace: 'nowrap',
                textOverflow: 'ellipsis',
                cursor: 'pointer',
              },
            }
          },
          customRender: (text, record) => (
            <a-tooltip placement="topLeft" title={record.nodeContent}>
              {record.nodeContent}
            </a-tooltip>
          ),
        },
        {
          title: '项目负责人',
          dataIndex: 'handlerUser',
          align: 'center',
          width: '90px',
          ellipsis: true,
        },
        {
          title: '合同约定日期',
          dataIndex: 'complateTime',
          align: 'center',
          scopedSlots: { customRender: 'complateTimeRender' },
          width: '100px',
          ellipsis: true,
        },
        {
          title: '实际完成日期',
          dataIndex: 'partaActualTime',
          align: 'center',
          scopedSlots: { customRender: 'actualTimeRender' },
          width: '100px',
          ellipsis: true,
        },
        {
          title: '预计完成日期',
          dataIndex: 'planTime',
          align: 'center',
          scopedSlots: { customRender: 'planTimeRender' },
          width: '100px',
          ellipsis: true,
        },
        {
          title: '是否逾期',
          dataIndex: 'nodeStatus',
          align: 'center',
          width: '80px',
          ellipsis: true,
          scopedSlots: { customRender: 'nodeStatusRender' },
        },
        {
          title: '逾期责任方',
          dataIndex: 'delayReason',
          align: 'center',
          width: '90px',
          ellipsis: true,
          scopedSlots: { customRender: 'delayReasonRender' },
        },
        {
          title: '付款节点内容',
          dataIndex: 'paymentContent',
          align: 'center',
          width: 'left',
          width: '140px',
          customCell: () => {
            return {
              style: {
                width: '140px',
                overflow: 'hidden',
                whiteSpace: 'nowrap',
                textOverflow: 'ellipsis',
                cursor: 'pointer',
              },
            }
          },
          customRender: (text, record) => (
            <a-tooltip placement="topLeft" title={record.paymentContent}>
              {record.paymentContent}
            </a-tooltip>
          ),
        },
        {
          title: '付款节点',
          dataIndex: 'isPayNode',
          align: 'center',
          scopedSlots: { customRender: 'isPayNodeRender' },
          width: '75px',
          ellipsis: true,
        },
        {
          title: '多个付款节点',
          dataIndex: 'isMutiContiditon',
          align: 'center',
          scopedSlots: { customRender: 'isMutiContiditonRender' },
          width: '100px',
          ellipsis: true,
        },
        {
          title: '合同金额',
          dataIndex: 'amount',
          align: 'center',
          width: '80px',
          ellipsis: true,
        },
        {
          title: '关联节点金额',
          dataIndex: 'paymentAmount',
          align: 'center',
          width: '100px',
          ellipsis: true,
        },
        {
          title: '税率',
          dataIndex: 'taxRate',
          align: 'center',
          width: '100px',
          ellipsis: true,
        },
        {
          title: '费用号',
          dataIndex: 'costNumber',
          align: 'center',
          width: '120px',
          ellipsis: true,
        },
        {
          title: '合同编号',
          dataIndex: 'contractNumber',
          align: 'center',
          width: '130px',
          ellipsis: true,
        },
        {
          title: '节点标识',
          dataIndex: 'nodeIdentify',
          width: '22%',
          align: 'center',
          width: '80px',
          ellipsis: true,
        },
      ],
      records: [],
      selectedRowKeys: [],
      selectedRow: [],
      pageSizeOptions: ['10', '20', '30', '40', '50'],
      searchForm: {
        total: 0,
        pageNo: 1,
        pageSize: 10,
      },
      tabLoading: false,
      currPageIndex: 1,
      currPageSize: 10,
      keyword: '',
      keywordType: '1',
      showSearchForm: false,
      myTaskCount: 0,
      urls: {
        deleteBetch: '/workReport/task/deleteBetch',
        codes: '/manage/codeInfo/queryByTypes',
        psCodes: '/hte/contract/codes',
        myPermission: '/workReport/project/myPermission',
        updateIsPayNode: '/workReport/task/updateIsPayNode',
        updateExecuteStatus: '/workReport/task/updateExecuteStatus',
      },
      codes: {},
      permission: [],
      showRelpaceHandlerUserByTask: false,
      isPayNode: '1',
      showIsPayNode: false,
      executeStatus: '5',
      showExecuteStatus: false,
      complateTime: [],
    }
  },
  computed: {
    projectId() {
      return this.$route.query && this.$route.query.projectId
    },
  },
  mounted() {
    this.getTaskList()
    // this.getMyTaskCount()

    this.fetchCodes()
    this.fetchPsCodes()
    this.fetchPermission()
  },
  methods: {
    calcDaysBetween,
    formatDate,
    fetchPermission() {
      getAction(this.urls.myPermission, { projectId: this.projectId }).then((res) => {
        if (res.success) {
          this.permission = res.result
        }
      })
    },
    checkPermission(powers) {
      let hasPower = false
      for (let p of powers) {
        if (this.permission.indexOf(p) > -1) {
          hasPower = true
          break
        }
      }
      return hasPower
    },
    fetchPsCodes() {
      postAction(this.urls.psCodes, { codes: ['contract_status'] }).then((res) => {
        if (res.success) {
          this.codes = { ...this.codes, ...res.result }
        }
      })
    },
    fetchCodes() {
      getAction(this.urls.codes, {
        types: 'WorkReportTaskStatus,IsPayNode,IsMutiContiditon,WorkReportDelayReson,WorkReportTaskAcceptStatus',
      }).then((res) => {
        if (res.success) {
          this.codes = { ...this.codes, ...res.result }
        }
      })
    },
    pageChange(pageNo, pageSize) {
      this.$set(this.searchForm, 'pageSize', pageSize)
      this.$set(this.searchForm, 'pageNo', pageNo)
      this.getTaskList()
    },
    handleTableChange(searchForm, filters, sorter) {
      this.$set(this.searchForm, 'sortField', 'item_index')
      this.$set(this.searchForm, 'sortOrder', sorter.order)
      this.getTaskList()
    },
    /**
     * 查询
     */
    handleSearch() {
      this.getTaskList()
    },
    changeKeyorkType() {
      if (this.keywordType == '1') {
        this.$set(this.searchForm, 'contractName', '')
      } else {
        this.$set(this.searchForm, 'contractNumber', '')
      }
    },
    handleToSearch() {
      this.onShowSizeChange()
      // this.getTaskList()
    },
    handleToCancel() {
      this.showSearchForm = false
    },
    openSearchForm() {
      this.showSearchForm = true
    },
    /**
     * 查询
     */
    getTaskList() {
      this.tabLoading = true
      if (this.complateTime[0]) {
        this.$set(this.searchForm, 'complateTimeStart', this.complateTime[0])
      }
      if (this.complateTime[1]) {
        this.$set(this.searchForm, 'complateTimeEnd', this.complateTime[1])
      }
      if (this.searchForm.statusArr) {
        this.$set(this.searchForm, 'status', this.searchForm.statusArr.join(','))
      } else {
        this.$set(this.searchForm, 'status', '')
      }
      if (this.searchForm.acceptStatusArr) {
        this.$set(this.searchForm, 'acceptStatus', this.searchForm.acceptStatusArr.join(','))
      } else {
        this.$set(this.searchForm, 'acceptStatus', '')
      }
      this.$set(this.searchForm, 'projectCode', this.projectCode)
      this.$set(this.searchForm, 'projectId', this.projectId)
      postAction('/workReport/task/page', this.searchForm).then((res) => {
        if (res.code == 200 && res.result) {
          this.selectedRowKeys = []
          this.selectedRow = []
          this.searchForm.total = res.result.total
          res.result.records.forEach((r, index) => {
            r.key = this.taskFlag + index

            if (r.isPayNode != '1' && r.nodeIdentify != '验收') {
              r.paymentStatus = '0'
            }
            if (
              (r.isPayNode == '1' || r.nodeIdentify != '验收') &&
              ['0', '1', '2', '3', '4', '5'].indexOf(r.status) > -1
            ) {
              r.paymentStatus = '1'
            }
            if (
              (r.isPayNode == '1' || r.nodeIdentify != '验收') &&
              ['6', '7', '8'].indexOf(r.status) > -1 &&
              r.paymentCount <= 0
            ) {
              r.paymentStatus = '2'
            }
            if (
              (r.isPayNode == '1' || r.nodeIdentify != '验收') &&
              ['6', '7', '8'].indexOf(r.status) > -1 &&
              r.paymentCount > 0 &&
              r.paymentCountActive <= 0
            ) {
              r.paymentStatus = '3'
            }
            if (
              (r.isPayNode == '1' || r.nodeIdentify != '验收') &&
              ['6', '7', '8'].indexOf(r.status) > -1 &&
              r.paymentCount > 0 &&
              r.paymentCountActive > 0
            ) {
              r.paymentStatus = '4'
            }
          })
          this.records = res.result.records
          this.tabLoading = false
        } else {
          this.$messageWorkReport.warning('数据加载失败:' + res.message)
          this.tabLoading = false
        }
        this.showSearchForm = false
      })
    },
    /**
     * 查询
     */
    getMyTaskCount() {
      let params = {}
      postAction('/workReport/task/myPage', params).then((res) => {
        if (res.code == 200 && res.result) {
          this.myTaskCount = res.result.total
        }
      })
    },

    doSearch() {
      this.$set(this.searchForm, 'pageNo', 1)
      this.getTaskList()
    },
    onSelectChange(selectedRowKeys, selectedRow) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRow = selectedRow
    },
    customRow(record) {
      return {
        on: {
          dblclick: (event) => {
            let urlJump = this.$router.resolve({ path: '/workReport/taskDetail/' + record.id })
            window.open(urlJump.href, '_blank')
          },
        },
      }
    },
    toTaskDetail(record) {
      let urlJump = this.$router.resolve({ path: '/workReport/taskDetail/' + record.id })
      window.open(urlJump.href, '_blank')
    },
    toMyTask() {
      let urlJump = this.$router.resolve({ path: '/workReport/myTaskList' })
      window.open(urlJump.href, '_blank')
    },
    toContractDetail() {
      if (this.selectedRow.length != 1) {
        this.$messageWorkReport.warning('请选择一条记录操作')
      } else {
        let urlJump = this.$router.resolve({ path: '/workReport/execute/' + this.selectedRow[0].projectId })
        window.open(urlJump.href, '_blank')
      }
    },
    toContractAttach() {
      if (this.selectedRow.length != 1) {
        this.$messageWorkReport.warning('请选择一条记录操作')
      } else {
        let urlJump = this.$router.resolve({ path: '/contract/attach/' + this.selectedRow[0].contractIdd })
        window.open(urlJump.href, '_blank')
      }
    },
    onShowSizeChange(pageNo, pageSize) {
      this.$set(this.searchForm, 'pageSize', pageSize)
      this.$set(this.searchForm, 'pageNo', 1)
      this.getTaskList()
    },
    removeTask() {
      if (this.selectedRowKeys.length == 0) {
        return this.$messageWorkReport.warning('请选择需要删除的行')
      }
      if (this.selectedRow.length > 0) {
        let flag = true
        for (let row of this.selectedRow) {
          if (['3', '4', '5', 3, 4, 5].indexOf(row.acceptStatus) > -1) {
            this.$messageWorkReport.warning('请请勿删除验收状态为【已发起】【已完成】【HIP已完成】的报工任务')
            flag = false
            break
          }
        }
        if (!flag) {
          return
        }
      }
      let that = this
      Modal.confirm({
        title: '确认删除',
        content: '是否删除选中数据?',
        onOk: function () {
          getAction(that.urls.deleteBetch, { ids: that.selectedRowKeys.join(',') }).then((res) => {
            if (res.success) {
              that.getTaskList()
            } else {
              that.$messageWorkReport.warning(res.message)
            }
          })
        },
      })
    },
    calcDelayType(record) {
      let _now = new Date()
      let complateTime = new Date(record.complateTime)
      if (!record.resultStatus || record.resultStatus == '0') {
        if (_now >= complateTime) {
          return 'red'
        }
        let expire = complateTime - _now
        if (expire <= 7 * 24 * 60 * 60 * 1000) {
          return 'yellow'
        }
      }
      if (record.resultStatus == '1') {
        let planTime = new Date(record.planTime)
        if (_now >= planTime) {
          return 'red'
        }
        let expire = planTime - _now
        if (expire <= 7 * 24 * 60 * 60 * 1000) {
          return 'yellow'
        }
      }
      return 'default'
    },
    exportExcle() {
      let url = process.env.VUE_APP_API_BASE_URL + '/workReport/task/export?1=1'
      if (this.complateTime[0]) {
        this.$set(this.searchForm, 'complateTimeStart', this.complateTime[0])
      }
      if (this.complateTime[1]) {
        this.$set(this.searchForm, 'complateTimeEnd', this.complateTime[1])
      }
      if (this.searchForm.statusArr) {
        this.$set(this.searchForm, 'status', this.searchForm.statusArr.join(','))
      } else {
        this.$set(this.searchForm, 'status', '')
      }
      if (this.searchForm.acceptStatusArr) {
        this.$set(this.searchForm, 'acceptStatus', this.searchForm.acceptStatusArr.join(','))
      } else {
        this.$set(this.searchForm, 'acceptStatus', '')
      }
      this.$set(this.searchForm, 'projectCode', this.projectCode)
      this.$set(this.searchForm, 'projectId', this.projectId)
      this.handleExportXls('报工任务', url, this.searchForm)
    },
    updateTaskUser() {
      if (this.selectedRowKeys.length <= 0) {
        return this.$messageWorkReport.warning('请选择需要更新项目负责人的记录')
      }
      this.showRelpaceHandlerUserByTask = true
    },
    closeRelpaceHandlerUserByTask(type) {
      if (type == 'flash') {
        this.handleSearch()
      }
      this.showRelpaceHandlerUserByTask = false
    },
    toPayment() {
      let urlJump = this.$router.resolve({ path: '/workReport/paymentList' })
      window.open(urlJump.href, '_blank')
    },
    toQuality() {
      let urlJump = this.$router.resolve({ path: '/workReport/qualityList' })
      window.open(urlJump.href, '_blank')
    },
    addTaskByProject() {
      let urlJump = this.$router.resolve({ path: '/workReport/addTask?projectId=' + this.projectId })
      window.open(urlJump.href, '_blank')
    },
    calcNodeStatus(record) {
      let endTime = new Date()
      if (record.partaStatus == '2') {
        endTime = record.partaActualTime ? record.partaActualTime + ' 23:59:59.999' : ''
      }
      let temp = this.calcDaysBetween(record.complateTime + ' 23:59:59.999', endTime)
      this.$set(record, 'partaNodeStatus', temp.status)
      if (temp.status != '正常') {
        this.$set(record, 'partaNodeDelayDays', temp.days)
        return record.partaNodeStatus + temp.days + '天'
      } else {
        this.$set(record, 'partaNodeDelayDays', 0)
        return record.partaNodeStatus
      }
    },
    tableRowClass(record, index) {
      if (parseInt(record.status) < 6) {
        if (new Date(record.complateTime) < new Date()) {
          return 'redRow'
        } else {
          var startDate = new Date(record.complateTime).getTime()
          var now = new Date()
          now.setHours(0)
          now.setMinutes(0)
          now.setSeconds(0)
          var endDate = now.getTime()
          var days = startDate - endDate
          if (days <= 15 * 86400 * 1000) {
            return 'greenRow'
          }
        }
      }
    },
    updateExecuteStatus() {
      if (this.selectedRowKeys && this.selectedRowKeys.length > 0) {
        getAction(
          this.urls.updateExecuteStatus +
            '?id=' +
            this.selectedRowKeys.join(',') +
            '&executeStatus=' +
            this.executeStatus
        ).then((res) => {
          if (res.success) {
            this.$messageWorkReport.success('标记成功')
            this.getTaskList()
            this.showExecuteStatus = false
          } else {
            this.$messageWorkReport.success('标记失败:' + res.message)
          }
        })
      } else {
        this.$messageWorkReport.warning('请至少选择一条记录进行操作')
      }
    },
    updateIsPayNode() {
      if (this.selectedRowKeys && this.selectedRowKeys.length > 0) {
        getAction(
          this.urls.updateIsPayNode + '?id=' + this.selectedRowKeys.join(',') + '&isPayNode=' + this.isPayNode
        ).then((res) => {
          if (res.success) {
            this.$messageWorkReport.success('标记成功')
            this.getTaskList()
            this.showIsPayNode = false
          } else {
            this.$messageWorkReport.success('标记失败:' + res.message)
          }
        })
      } else {
        this.$messageWorkReport.warning('请至少选择一条记录进行操作')
      }
    },
  },
  watch: {
    // projectId: {
    //   handler(newV, oldV) {
    //     this.getTaskList()
    //   },
    //   deep: true,
    //   immediate: true,
    // },
  },
}
</script>

<style lang="less" scoped>
@import '~@assets/less/hte-main.less';
.page-main {
  .banner {
    background-image: url(~@assets/contract-top.png);
  }
  .container {
    .content-list {
      margin-top: 15px;
    }
  }
  .font-active {
    cursor: pointer;
  }
}
.contentStyle-default {
  display: block;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.contentStyle-red {
  display: block;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: red;
}
.contentStyle-yellow {
  display: block;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: burlywood;
}
/deep/.greenRow {
  color: green;
}
/deep/.redRow {
  color: red;
}
</style>
